home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / X11R4 / cmds / X / ddx / mfb / mfbfillrct.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-02-15  |  4.4 KB  |  165 lines

  1. /* Combined Purdue/PurduePlus patches, level 2.0, 1/17/89 */
  2. /***********************************************************
  3. Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts,
  4. and the Massachusetts Institute of Technology, Cambridge, Massachusetts.
  5.  
  6.                         All Rights Reserved
  7.  
  8. Permission to use, copy, modify, and distribute this software and its 
  9. documentation for any purpose and without fee is hereby granted, 
  10. provided that the above copyright notice appear in all copies and that
  11. both that copyright notice and this permission notice appear in 
  12. supporting documentation, and that the names of Digital or MIT not be
  13. used in advertising or publicity pertaining to distribution of the
  14. software without specific, written prior permission.  
  15.  
  16. DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  17. ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  18. DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  19. ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  20. WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  21. ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  22. SOFTWARE.
  23.  
  24. ******************************************************************/
  25. /* $XConsortium: mfbfillrct.c,v 5.5 89/11/24 18:04:31 rws Exp $ */
  26. #include "X.h"
  27. #include "Xprotostr.h"
  28. #include "pixmapstr.h"
  29. #include "gcstruct.h"
  30. #include "windowstr.h"
  31. #include "miscstruct.h"
  32. #include "regionstr.h"
  33. #include "scrnintstr.h"
  34.  
  35. #include "mfb.h"
  36. #include "maskbits.h"
  37.  
  38. #define MODEQ(a, b) ((a) %= (b))
  39. void mfbPaintOddSize();
  40.  
  41. /* 
  42.     filled rectangles.
  43.     translate the rectangles, clip them, and call the
  44. helper function in the GC.
  45. */
  46.  
  47. void
  48. mfbPolyFillRect(pDrawable, pGC, nrectFill, prectInit)
  49.     DrawablePtr pDrawable;
  50.     GCPtr    pGC;
  51.     int        nrectFill;     /* number of rectangles to fill */
  52.     xRectangle    *prectInit;      /* Pointer to first rectangle to fill */
  53. {
  54.     int xorg, yorg;
  55.     register int n;        /* spare counter */
  56.     register xRectangle *prect; /* temporary */
  57.     RegionPtr prgnClip;
  58.     register BoxPtr pbox;    /* used to clip with */
  59.     register BoxPtr pboxClipped;
  60.     BoxPtr pboxClippedBase;
  61.     register BoxPtr pextent;
  62.     mfbPrivGC    *priv;
  63.     int alu;
  64.     void (* pfn) ();
  65.     PixmapPtr ppix;
  66.     int numRects;
  67.  
  68.     priv = (mfbPrivGC *) pGC->devPrivates[mfbGCPrivateIndex].ptr;
  69.     alu = priv->ropFillArea;
  70.     pfn = priv->FillArea;
  71.     ppix = priv->pRotatedPixmap;
  72.     prgnClip = priv->pCompositeClip;
  73.  
  74.     numRects = REGION_NUM_RECTS(prgnClip);
  75.     pboxClippedBase = (BoxPtr)ALLOCATE_LOCAL(numRects * sizeof(BoxRec));
  76.  
  77.     if (!pboxClippedBase)
  78.     return;
  79.  
  80.     prect = prectInit;
  81.     xorg = pDrawable->x;
  82.     yorg = pDrawable->y;
  83.     if (xorg || yorg)
  84.     {
  85.         prect = prectInit;
  86.     n = nrectFill;
  87.     Duff (n, prect->x += xorg; prect->y += yorg; prect++);
  88.     }
  89.  
  90.     prect = prectInit;
  91.  
  92.     pextent = (*pGC->pScreen->RegionExtents)(prgnClip);
  93.  
  94.     while (nrectFill--)
  95.     {
  96.     BoxRec box;
  97.     int    x2, y2;
  98.  
  99.     /*
  100.      * clip the box to the extent of the region --
  101.      * avoids overflowing shorts and minimizes other
  102.      * computations
  103.      */
  104.  
  105.     box.x1 = prect->x;
  106.     if (box.x1 < pextent->x1)
  107.         box.x1 = pextent->x1;
  108.  
  109.     box.y1 = prect->y;
  110.     if (box.y1 < pextent->y1)
  111.         box.y1 = pextent->y1;
  112.  
  113.     x2 = (int) prect->x + (int) prect->width;
  114.     if (x2 > pextent->x2)
  115.         x2 = pextent->x2;
  116.     box.x2 = x2;
  117.  
  118.     y2 = (int) prect->y + (int) prect->height;
  119.     if (y2 > pextent->y2)
  120.         y2 = pextent->y2;
  121.     box.y2 = y2;
  122.  
  123.     prect++;
  124.  
  125.     if ((box.x1 >= box.x2) || (box.y1 >= box.y2))
  126.         continue;
  127.  
  128.     switch((*pGC->pScreen->RectIn)(prgnClip, &box))
  129.     {
  130.       case rgnOUT:
  131.         break;
  132.       case rgnIN:
  133.         (*pfn)(pDrawable, 1, &box, alu, ppix);
  134.         break;
  135.       case rgnPART:
  136.         pboxClipped = pboxClippedBase;
  137.         pbox = REGION_RECTS(prgnClip);
  138.         n = numRects;
  139.  
  140.         /* clip the rectangle to each box in the clip region
  141.            this is logically equivalent to calling Intersect()
  142.         */
  143.         while(n--)
  144.         {
  145.             pboxClipped->x1 = max(box.x1, pbox->x1);
  146.             pboxClipped->y1 = max(box.y1, pbox->y1);
  147.             pboxClipped->x2 = min(box.x2, pbox->x2);
  148.             pboxClipped->y2 = min(box.y2, pbox->y2);
  149.         pbox++;
  150.  
  151.             /* see if clipping left anything */
  152.             if(pboxClipped->x1 < pboxClipped->x2 && 
  153.                pboxClipped->y1 < pboxClipped->y2)
  154.             {
  155.             pboxClipped++;
  156.             }
  157.         }
  158.         (*pfn)(pDrawable, pboxClipped-pboxClippedBase, 
  159.            pboxClippedBase, alu, ppix);
  160.         break;
  161.     }
  162.     }
  163.     DEALLOCATE_LOCAL(pboxClippedBase);
  164. }
  165.